package com.llt.lg.slice;

import com.llt.bottomnavigationf.OnGetFractionUtil;
import com.llt.bottomnavigationf.OnItemClickListener;
import com.llt.bottomnavigationf.OnNavClickListener;
import com.llt.bottomnavigationf.Scaffold;
import com.llt.bottomnavigationf.entity.AppBar;
import com.llt.bottomnavigationf.entity.Body;
import com.llt.bottomnavigationf.entity.BottomNavItem;
import com.llt.bottomnavigationf.entity.BottomNavigation;
import com.llt.bottomnavigationf.fraction.FractionUtil;
import com.llt.bottomnavigationf.util.LogUtil;
import com.llt.bottomnavigationf.util.RouterUtil;
import com.llt.lg.BottomNavViewModel;
import com.llt.lg.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.ability.fraction.Fraction;
import ohos.aafwk.ability.fraction.FractionAbility;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.LayoutScatter;

import java.util.List;

public class MainAbilitySlice extends AbilitySlice {
    public FractionUtil fractionUtil;
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        present(this,intent);
        DirectionalLayout parse =(DirectionalLayout) LayoutScatter.getInstance(getContext()).parse(ResourceTable.Layout_ability_main, null, false);
        AppBar appBar = new AppBar();
        appBar.setTitle("自定义导航");
        appBar.setLeadingId(ResourceTable.Media_arrow_left);
        BottomNavigation bottomNavigation = new BottomNavigation();
        BottomNavViewModel bottomNavViewModel = new BottomNavViewModel();
        bottomNavigation.setBottomNavItems(bottomNavViewModel.initBottomNavFractions());
        List<Fraction> fractions = bottomNavViewModel.initBottomNavFractionsBody(this);
        Body body = new Body();
        body.setFractions(fractions);
//        appBar
        Scaffold init = new Scaffold((((FractionAbility) getAbility())),appBar, body, bottomNavigation).init();
        Component scaffold = init.getScaffold();
        parse.addComponent(scaffold);
        init.getGetFractionUtil(new OnGetFractionUtil() {
            @Override
            public void getFractionUtil(FractionUtil fraction) {
               fractionUtil = fraction;
            }
        });

        init.setOnNavClickListener(new OnNavClickListener() {
            @Override
            public void onLeading() {
//                fractionUtil.show(1);
                goTO();
                LogUtil.info("点击顶部导航左边按钮", "点击了");
            }
        });
        init.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onTap(int index) {
                LogUtil.info("点击底部导航返回当前索引值", Integer.toString(index));
            }
        });
        setUIContent(parse);
    }
    private void goTO(){
        try {
            RouterUtil.navigate(this,new Routerdmeo2Slice());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    @Override
    public void onActive() {
        super.onActive();
    }
    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
